#include "db.h"

#include "in.h"

int test_create_tables()
{
	struct MemDatabase	*db = NULL ;
	struct MemTable		*table = NULL ;
	
	int			nret = 0 ;
	
	db = MDBCreateDatabase( "mydb" ) ;
	if( db == NULL )
	{
		printf( "ERROR : MDBCreateDatabase failed[%d]\n" , MDBGetLastError() );
		return -1;
	}
	else
	{
		printf( "MDBCreateDatabase ok\n" );
	}
	
	table = MDBCreateTable( db , "mytable" , sizeof(struct UserInfo) ) ;
	if( table == NULL )
	{
		printf( "ERROR : MDBCreateTable \"mytable\" failed[%d]\n" , MDBGetLastError() );
		return -1;
	}
	else
	{
		printf( "MDBCreateTable \"mytable\" ok\n" );
	}
	
	table = MDBCreateTable( db , "mytable2" , sizeof(struct UserInfo) ) ;
	if( table == NULL )
	{
		printf( "ERROR : MDBCreateTable \"mytable2\" failed[%d]\n" , MDBGetLastError() );
		return -1;
	}
	else
	{
		printf( "MDBCreateTable \"mytable2\" ok\n" );
	}
	
	table = MDBQueryTable( db , "mytable" ) ;
	if( table == NULL )
	{
		printf( "ERROR : MDBQueryTable \"mytable\" failed[%d]\n" , MDBGetLastError() );
		return -1;
	}
	else
	{
		printf( "MDBQueryTable \"mytable\" ok\n" );
	}
	
	nret = MDBDropTableDirectly( db , table ) ;
	if( nret )
	{
		printf( "ERROR : MDBDropTableDirectly \"mytable\" failed[%d]\n" , MDBGetLastError() );
		return -1;
	}
	else
	{
		printf( "MDBDropTableDirectly \"mytable\" ok\n" );
	}
	
	nret = MDBDropTable( db , "mytable2" ) ;
	if( nret )
	{
		printf( "ERROR : MDBDropTable \"mytable2\" failed[%d]\n" , MDBGetLastError() );
		return -1;
	}
	else
	{
		printf( "MDBDropTable \"mytable2\" ok\n" );
	}
	
	MDBDropDatabase( db );
	printf( "MDBDropDatabase ok\n" );
	
	return 0;
}

int main()
{
	return -test_create_tables();
}

